#include <iostream>
using namespace std;

int bitsum(int n)
{
    int sum = 0;
    while(n)
    {
        sum += (n % 10) * (n % 10);
        n /= 10;
    }
    return sum;
}
bool isHappy(int n)
{

    int slow = n, fast = bitsum(n);
    while(slow != fast)
    {
        slow = bitsum(slow);
        fast = bitsum(bitsum(fast));
    }
    if(fast == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
    cout << isHappy(19) << endl;
    return 0;
}